﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iPhOwa.Exchange.WebDav.Methods
{
	/// <summary>
	/// The put method.
	/// </summary>
	internal sealed class Put : Method
	{
		private readonly IDictionary<string, string> headers;
		private readonly string content;
		private readonly string contentType;

		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="path"></param>
		/// <param name="session"></param>
		/// <param name="content"></param>
		/// <param name="headers"></param>
		/// <param name="contentType"></param>
		public Put(Uri path, OwaSession session, string content, IDictionary<string, string> headers, string contentType)
			: base(path, session)
		{
			this.headers = headers;
			this.content = content;
			this.contentType = contentType;
		}

		/// <summary>
		/// Command name.
		/// </summary>
		public override string Name
		{
			get { return "PUT"; }
		}

		/// <summary>
		/// The method content type.
		/// </summary>
		public override string ContentType
		{
			get
			{
				return contentType;
			}
		}

		protected override string BuildCommand()
		{
			return content;
		}

		protected override void AddHeaders(System.Net.HttpWebRequest request)
		{
			foreach (KeyValuePair<string, string> header in headers)
			{
				request.Headers.Add(header.Key, header.Value);
			}
		}

		/// <summary>
		/// Run the search.
		/// </summary>
		public void Run()
		{
			Execute();
		}
	}
}
